#include <QSerialPortInfo>
#include <QSettings>
#include "ConnectWindowTCP.h"
#include "ui_ConnectWindowTCP.h"
#include <QDebug>

#define CONFIG_FILENAME "config.ini"

ConnectWindowTCP::ConnectWindowTCP(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ConnectWindowTCP)
{
    ui->setupUi(this);
    connect(ui->btnConnect, &QPushButton::clicked, this, &ConnectWindowTCP::connectClicked);

    ui->leditIP->setText(QSettings(CONFIG_FILENAME, QSettings::IniFormat).value("ip", "10.0.0.2").toString());
    ui->spboxPort->setValue(QSettings(CONFIG_FILENAME, QSettings::IniFormat).value("port", 502).toInt());
}

ConnectWindowTCP::~ConnectWindowTCP()
{
    QSettings(CONFIG_FILENAME, QSettings::IniFormat).setValue("ip", ui->leditIP->text());
    QSettings(CONFIG_FILENAME, QSettings::IniFormat).setValue("port", ui->spboxPort->value());
    delete ui;
}

void ConnectWindowTCP::connectClicked()
{
    this->close();  // 关闭窗口
    emit initConnect(ui->leditIP->text(), ui->spboxPort->value());
}
